package com.nf.health.app.utils;

import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.nf.health.app.MyApplication;
import com.nf.health.app.chatservice.bean.StatusBean;

import java.util.List;

/**
 * Created by Administrator on 2017/2/27/027.
 */

public class DealUiUtils {


    public static void setMyConactTextConMsg(StatusBean mStatusBean, final TextView tv_content_contact, final LinearLayout ll_arrow_right, final TextView tv_arrow_contact_bottom,
                                             TextView ic_title_contactleft, LinearLayout ll_contact_content) {
        StatusBean.Remark01Bean remark01 = mStatusBean.getRemark01();
        if(remark01 != null){
            List<StatusBean.Remark01Bean.UsersBean> users = remark01.getUsers();
            if(users != null){
                if(users.size() > 0){
                    ll_contact_content.setVisibility(View.VISIBLE);
                }else{
                    return ;
                }
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i <users.size() ; i++) {
                    if(sb.length() > 0 ){
                        sb.append(",");
                    }
                    String nameArray =  users.get(i).getRname();
                    if(TextUtils.isEmpty(nameArray)){
                        nameArray = users.get(i).getNick();
                    }
                    if(!TextUtils.isEmpty(nameArray)){
                        sb.append(nameArray);
                    }
                }

                tv_content_contact.setText(sb.toString());
                ic_title_contactleft.setText(mStatusBean.getRemark01().getTitle()+": ");//设置title
                tv_content_contact.setMaxLines(1);
                int textViewContentLength  = DensityUtil.getScreenIntWidth(MyApplication.getContext()) - DensityUtil.dip2px(MyApplication.getContext(),30+70+10) ;
                Paint  paint =  tv_content_contact.getPaint();
                float realLength = paint.measureText(sb.toString());
                if(realLength > textViewContentLength+DensityUtil.dip2px(MyApplication.getContext(),30 - 10)){//  实际长度 > TextView的长度
                    ll_arrow_right.setVisibility(View.VISIBLE);
                    tv_arrow_contact_bottom.setVisibility(View.GONE);
                    tv_content_contact.setMaxLines(1);
                }else{
                    ll_arrow_right.setVisibility(View.GONE);
                    tv_arrow_contact_bottom.setVisibility(View.GONE);
                    tv_content_contact.setMaxLines(1);
                }
            }
            ll_arrow_right.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    tv_content_contact.setMaxLines(Integer.MAX_VALUE);
                    ll_arrow_right.setVisibility(View.GONE);
                    tv_arrow_contact_bottom.setVisibility(View.VISIBLE);
                }
            });
            tv_arrow_contact_bottom.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    tv_content_contact.setMaxLines(1);
                    ll_arrow_right.setVisibility(View.VISIBLE);
                    tv_arrow_contact_bottom.setVisibility(View.GONE);

                }
            });
        }
    }
}
